@extends('layouts.default')
@section('content')
    @auth
        <form action="{{route('blog.store')}}" method="post">
            @csrf
            <div class="card">
                <div class="card-header">
                    发表博客
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="">博文</label>
                        <textarea class="form-control" name="content" id="" rows="3">{{old('content')}}</textarea>
                    </div>
                </div>
                <div class="card-footer text-muted">
                    <button class="btn btn-success" type="submit">发表博客</button>
                </div>
            </div>
        </form>
    @endauth
    <div class="card mt-4">
        <div class="card-header">
            博客列表
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th width="100px">编号</th>
                    <th>博文</th>
                    <th width="200px">作者</th>
                    <th width="200px">发表时间</th>
                    <th width="200px">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($blogs as $blog)
                    <tr>
                        <td scope="row">{{$blog -> id}}</td>
                        <td>{{$blog -> content}}</td>

                        <td>
                            <a href="{{route('user.show',$blog->user->id)}}">
                                {{$blog -> user -> name}}
                            </a>
                        </td>

                        <td>{{$blog -> created_at }}</td>
                        <td>
                            @can('delete',$blog)
                                <form action="{{route('blog.destroy',$blog)}}" method="post">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-danger">删除</button>
                                </form>
                            @endcan
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="card-footer text-muted">
            {{$blogs -> links()}}
        </div>
    </div>
@endsection
